********************************************************************************
*                                                                              *
* This do file reproduces all tables related to the DiD empirical strategy
* and related robustness checks.    *
*                                                                              *
********************************************************************************

set scrollbufsize 2048000

set more off

 clear matrix
 clear
 set mem 330m 
 
***************

 * Change directory (cd) to your working folder path  
 * cd "your directory"
 
* Data set
use	"DiD.dta"

********************************************************************************
*                             Appendix Tables 16 and 17                     *
********************************************************************************
tab autodefensa if period==1
tab autodefensa if period==3
 

********************************************************************************
*                          Appendix Tables 18-20                         *
********************************************************************************
* Creating a data set with observations from period 3 
keep if period==3
save "DiD_p3.dta", replace

* Data: only from period 3
use "DiD_p3.dta", clear

tab autodefensa, missing
tab violence_est_period2, missing

* Using the propensity score module developed by Becker and Ichino (2002)
* * the pscore command gives information to create Appendix Tables 18 and 19

pscore violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist, pscore(ps1) blockid(block1) comsup
estimates store pscore

label variable sendero82 "Prior Insurgent Presence" 
label variable emzone "Initial Military Rule"
label variable violence_sl_period1 "Prior Insurgent Violence"
label variable provcap_dist "Distance to Province Capital"

* Table 18
#delimit ;
estout pscore using pscore.tex, cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi$^{2} N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr


********************************************************************************

* Sample: Common support 

* Dropping 'untreated' units outside of common support:
drop if block1==.
 
keep id violence_est_period2

merge 1:m id using "DiD.dta"
 
*unmerged units correspond to the units outside common support

drop if _merge==2

recode period(1=0)
recode period(3=1)
 
drop _merge 

save "DiD_cs.dta", replace

********************************************************************************
*                               Appendix Table 21                           *
********************************************************************************
* Sample: common support
use "DiD_cs.dta", clear

keep if period==1

summarize autodefensa_1 autodefensa violence_est_period2 emzone sendero82 violence_sl_period1 provcap_dist

label variable autodefensa_1 "Autodefensa Mobilization (Pre)"
label variable autodefensa "Autodefensa Mobilization (Post)"
label variable violence_est_period2 "State Violence"
label variable emzone "Initial Military Rule"
label variable sendero82 "Prior Insurgent Presence" 
label variable violence_sl_period1 "Prior Insurgent Violence"
label variable provcap_dist "Distance to Province Capital"


sutex autodefensa_1 autodefensa violence_est_period2 emzone sendero82 violence_sl_period1 provcap_dist, labels minmax title(Descriptive Statistics (Common Support PS I; N = 11,958)) file(table21app.tex) replace

********************************************************************************
*                               Appendix Table 22                              *
********************************************************************************

sum autodefensa_1 if violence_est_period2==1
sum autodefensa if violence_est_period2==1

sum autodefensa_1 if violence_est_period2==0
sum autodefensa if violence_est_period2==0
  
********************************************************************************

********************************************************************************
*                              Main Paper Table 3                              *
********************************************************************************
use "DiD_cs.dta", clear

label variable sendero82 "Prior Insurgent Presence"
label variable emzone "Initial Military Rule"
label variable violence_sl_period1 "Prior Insurgent Violence"
label variable provcap_dist "Distance to Prov. Capital"
label variable violence_est_period2 "State Violence"
label variable period "Period"


reg autodefensa i.period##i.violence_est_period2, cluster(id) 
estimates store per1 
 
reg autodefensa i.period##i.violence_est_period2, cluster(ccdi) 
estimates store per2

reg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist, cluster(id)
estimates store per3

reg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist, cluster(ccdi)
estimates store per4

    #delimit ;
estout per1 per2 per3 per4 using table3did.tex, cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0g) labels(Rsquared Clusters N)) 
label title(OLS Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lllll}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr


********************************************************************************
*                               Appendix Table  23                             *
********************************************************************************

reg autodefensa i.period##i.violence_est_period2 if ccdd=="05", cluster(id) 
estimates store aya1
 
reg autodefensa i.period##i.violence_est_period2 if ccdd=="05", cluster(ccdi) 
estimates store aya2

reg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist if ccdd=="05", cluster(id)
estimates store aya3

reg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist if ccdd=="05", cluster(ccdi)
estimates store aya4

    #delimit ;
estout aya1 aya2 aya3 aya4 using table23app.tex, cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0g) labels(Rsquared Clusters N)) 
label title(OLS Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lllll}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr


********************************************************************************
*                               Appendix Table  24                             *
********************************************************************************
preserve

xtset ccdi

xtreg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist, fe cluster(ccdi)
estimates store fixedccdi

restore

areg autodefensa i.period##i.violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist i.ccdi, absorb(ccdi) vce(cluster id)
estimates store fixedccdiidcluster

    #delimit ;
estout fixedccdi fixedccdiidcluster using table24app.tex, cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0g) labels(Rsquared Clusters N)) 
label title(OLS Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr


********************************************************************************
*                               Appendix Table  25                            *
********************************************************************************

preserve

keep if period==0

tab autodefensa violence_est_period2
reg autodefensa violence_est_period2, robust
estimates store pre1
reg autodefensa violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist, robust
estimates store pre2



    #delimit ;
estout pre1 pre2 using table25app.tex, cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0g) labels(Rsquared Clusters N)) 
label title(OLS Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lll}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr
restore


********************************************************************************
*                          Appendix Tables 26, 27 and 28                         *
********************************************************************************
 
* Data: only from period 3
use "DiD_p3.dta", clear

* the pscore command gives information to create Appendix Tables 27 and 28
 
pscore violence_est_period2 sendero82 emzone violence_sl_period1 provcap_dist autodefensa_1, pscore(ps2) blockid(block2) comsup
estimates store pscore2

label variable sendero82 "Prior Insurgent Presence" 
label variable emzone "Initial Military Rule"
label variable violence_sl_period1 "Prior Insurgent Violence"
label variable provcap_dist "Distance to Province Capital"
label variable autodefensa_1 "Autodefensa Mobilization (Pre)"

 
* Appendix Table 26
 #delimit ;
estout pscore2 using pscore2.tex, cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi$^{2} N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr


********************************************************************************

* Sample: Common support 

* Dropping 'untreated' units outside of common support:
drop if block2==.
 
keep id violence_est_period2
sort id 

merge 1:m id using "DiD.dta"
 
*unmerged units correspond to the units outside common support

drop if _merge==2

drop if period==2
drop if period==4
 
recode period(1=0)
recode period(3=1)

keep if period==1

********************************************************************************
*                                Appendix Table 29                             *
********************************************************************************
label variable autodefensa "Autodefensa Mobilization (Post)"
label variable violence_est_period2 "State Violence"
label variable emzone "Initial Military Rule"
label variable sendero82 "Prior Insurgent Presence" 
label variable violence_sl_period1 "Prior Insurgent Violence"
label variable provcap_dist "Distance to Province Capital"
label variable autodefensa_1 "Autodefensa Mobilization (Pre)"

reg autodefensa violence_est_period2, robust
estimates store pro1

reg autodefensa violence_est_period2, cluster(ccdi) 
estimates store pro2

reg autodefensa violence_est_period2 autodefensa_1 sendero82 emzone violence_sl_period1 provcap_dist, robust
estimates store pro3

reg autodefensa violence_est_period2 autodefensa_1 sendero82 emzone violence_sl_period1 provcap_dist, cluster(ccdi)
estimates store pro4
  
    #delimit ;
estout pro1 pro2 pro3 pro4 using table29app.tex, cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0g) labels(Rsquared Clusters N)) 
label title(OLS Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lllll}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}") replace;
#delimit cr
 
 


